/*******************************************************************************
 * Copyright (c) 2012 March and Conquest.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package mrusanov.towers.main.ui;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import mrusanov.towers.localization.Localization;
import mrusanov.towers.players.Tower;

public class TowerPanel extends JPanel {
	private static final long serialVersionUID = -1139455091908840074L;

	private Tower tower;

	private final JTextArea lastTurnTextField;
	private final JLabel towerLabel;
	private final JLabel wallLabel;

	public TowerPanel() {

		towerLabel = new JLabel();
		towerLabel.setFont(MainForm.BOLD_FONT);
		wallLabel = new JLabel();
		wallLabel.setFont(MainForm.BOLD_FONT);
		lastTurnTextField = new JTextArea();
		lastTurnTextField.setEditable(false);
		lastTurnTextField.setLineWrap(true);
		lastTurnTextField.setWrapStyleWord(true);

		setLayout(new GridLayout(3, 1));
		add(new JScrollPane(lastTurnTextField));
		add(towerLabel);
		add(wallLabel);

		refreshLabels();
	}

	void setTower(Tower tower) {
		this.tower = tower;
	}

	public void refreshLabels() {
		if (tower == null) {
			return;
		}

		towerLabel.setText(Localization.getString("ui.tower") + " " + tower.getTowerHeight());
		wallLabel.setText(Localization.getString("ui.wall") + " " + tower.getWallHeight());
	}

	public void setTextToTextField(String text) {
		lastTurnTextField.setText(text);
	}

	public void addTextToTextField(String text) {
		if (lastTurnTextField.getText().length() != 0) {
			lastTurnTextField.append("\n");
		}

		lastTurnTextField.append(text);
	}
}
